//
//  ZHHorizontalButton.m
//  sc-cyan-ios
//
//  Created by lj on 2017/12/26.
//  Copyright © 2017年 greenbuilding. All rights reserved.
//

#import "ZHHorizontalButton.h"

@implementation ZHHorizontalButton

- (void)setup{
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}

- (void)awakeFromNib{
    
    [super awakeFromNib];
    self.autoresizingMask = UIViewAutoresizingNone;
    [self setup];
}


- (void)layoutSubviews{
    [super layoutSubviews];

    [self setUpFrame:5];
}

- (void)setSpace:(CGFloat)space{
    _space = space;
    [self setUpFrame:space];
    
}

- (void)setUpFrame:(CGFloat)space{
    //文字和图片的总宽度
    CGFloat tw = [self.titleLabel.text sizeWithFont:self.titleLabel.font andMaxSize:CGSizeMake(MAXFLOAT, self.height)].width + self.imageView.width + space;
    
    //调整位置
    self.titleLabel.x = (self.width - tw) * 0.5;
    self.titleLabel.y = 0;
    self.titleLabel.height = self.height;
    
    //调整图片
    self.imageView.x = CGRectGetMaxX(self.titleLabel.frame) + space;
}


@end
